# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

Group.delete_all
admin_group     =  Group.create(name: '管理员')
group_xinxiyuan =  Group.create(name: '信息员')
group_xinmeiti  =  Group.create(name: '新媒体组')
group_xiaobao   =  Group.create(name: '校报组')
group_meiti     =  Group.create(name: '媒体华理组')
group_jizhe     =  Group.create(name: '记者组')
group_liulan    =  Group.create(name: '浏览组')
group_guidang   =  Group.create(name: '归档组')
group_waixuan   =  Group.create(name: '外宣组')

xinxi_user = User.create(email: 'xinxiyuan@ecust.edu.cn', name: '信息员用户', password: '12345678')
xinmeiti_user = User.create(email: 'xinmeitizu@ecust.edu.cn', name: '新媒体组用户', password: '12345678')
xiaobao_user = User.create(email: 'xiaobaozu@ecust.edu.cn', name: '校报组用户', password: '12345678')
meiti_user = User.create(email: 'meitihualizu@ecust.edu.cn', name: '媒体华理组用户', password: '12345678')
jizhe_user = User.create(email: 'jizhezu@ecust.edu.cn', name: '记者组用户', password: '12345678')
liulan_user = User.create(email: 'liulanzu@ecust.edu.cn', name: '浏览组用户', password: '12345678')
guidang_user = User.create(email: 'guidangzu@ecust.edu.cn', name: '归档组用户', password: '12345678')
waixuan_user = User.create(email: 'waixuanzu@ecust.edu.cn', name: '外宣组', password: '12345678')
admin_user = User.create(email: 'chaojiguanliyuan@ecust.edu.cn', name: '管理员用户', password: '12345678')

Department.create(:name => "校党")
Department.create(:name => "宣传部")
Department.create(:name => "教师部")

user_permission = Permission.create(:ability => "manage", :class_name => "User", :describe => "用户管理")
news_permission = Permission.create(:ability => "manage", :class_name => "News", :describe => "新闻管理")
top_news_permission = Permission.create(:ability => "manage", :class_name => "TopNews", :describe => "大图新闻管理")
new_medium_permission = Permission.create(:ability => "manage", :class_name => "NewMedium", :describe => "新媒体入口管理")

GroupPermission.new(:group_id => admin_group.id, :permission_id => user_permission.id).save
GroupPermission.new(:group_id => admin_group.id, :permission_id => news_permission.id).save
GroupPermission.new(:group_id => admin_group.id, :permission_id => top_news_permission.id).save
GroupPermission.new(:group_id => admin_group.id, :permission_id => new_medium_permission.id).save

#1:管理员  6:信息员 12:媒体华理 14:归档,这些是老数据库的group_id,改成新数据库的group_id,就是将老用户跟新的组对应起来
groups_users = GroupUser.all
groups_users.each do |gp_user|
  p gp_user.group_id
  case gp_user.group_id
    when 1
      gp_user.group_id = admin_group.id
    when 6
      gp_user.group_id = group_xinxiyuan.id
    when 12
      gp_user.group_id = group_meiti.id
    when 14
      gp_user.group_id = group_guidang.id
  end
  gp_user.save
  p gp_user.group_id
end
GroupUser.create(:group_id => group_xinxiyuan.id, :user_id => xinxi_user.id)
GroupUser.create(:group_id => group_xinmeiti.id, :user_id => xinmeiti_user.id)
GroupUser.create(:group_id => group_xiaobao.id, :user_id => xiaobao_user.id)
GroupUser.create(:group_id => group_meiti.id, :user_id => meiti_user.id)
GroupUser.create(:group_id => group_jizhe.id, :user_id => jizhe_user.id)
GroupUser.create(:group_id => group_liulan.id, :user_id => liulan_user.id)
GroupUser.create(:group_id => group_guidang.id, :user_id => guidang_user.id)
GroupUser.create(:group_id => group_waixuan.id, :user_id => waixuan_user.id)
GroupUser.create(:group_id => admin_group.id, :user_id => admin_user.id)


 # 1431  cd /var/www/hdlg_news/current && ( RVM_PATH=/home/louis/.rvm/ RAILS_ENV=production /var/www/hdlg_news/rvm1scripts/rvm-auto.sh 2.0.0 bundle exec rake db:drop)
 # 1432  ps ax | grep unicorn
 # 1433  kill -9 8851
 # 1434  cd /var/www/hdlg_news/current && ( RVM_PATH=/home/louis/.rvm/ RAILS_ENV=production /var/www/hdlg_news/rvm1scripts/rvm-auto.sh 2.0.0 bundle exec rake db:drop)
 # 1435  cd /var/www/hdlg_news/current && ( RVM_PATH=/home/louis/.rvm/ RAILS_ENV=production /var/www/hdlg_news/rvm1scripts/rvm-auto.sh 2.0.0 bundle exec rake db:create)
 # 1436  histroy | grep hdlg_news_production
 # 1437  history | grep hdlg_news_production
 # 1438  pg_restore --host 127.0.0.1 --port 5432 --username "postgres" --dbname "hdlg_news_production" --role "postgres" --verbose "/home/louis/hdlg_new_db"
 # 1439  cd /var/www/hdlg_news/current && ( RVM_PATH=/home/louis/.rvm/ RAILS_ENV=production /var/www/hdlg_news/rvm1scripts/rvm-auto.sh 2.0.0 bundle exec rake db:migrate)
 # 1440  cd /var/www/hdlg_news/current && ( RVM_PATH=/home/louis/.rvm/ RAILS_ENV=production /var/www/hdlg_news/rvm1scripts/rvm-auto.sh 2.0.0 bundle exec rake db:seed)
 # 1441  cd /var/www/hdlg_news/current && ( RVM_PATH=/home/louis/.rvm/ RAILS_ENV=production /var/www/hdlg_news/rvm1scripts/rvm-auto.sh 2.0.0 bundle exec unicorn -c /var/www/hdlg_news/current/config/unicorn/production.rb -E production -D  )
 # 1442  history


# 10208  rake db:drop
# 10209  rake db:create
# 10210  pg_restore --host 127.0.0.1 --port 5432 --username "postgres" --dbname "hdlg_news_development" --role "postgres" --verbose "/Users/louis/hdlg_new_db"
# 10211  rake db:migrate
# 10212  rake db:seed




# 10312* rake db:drop
# 10316  rake db:create
# 10317  rake db:migrate
# 10318  rake mysql_import:data
# 10315  rake mysql_import:new
# 10320  rake db:seed